using SharpDX.Direct3D11;
using System;

namespace Engine.Graphics.Shaders.C11UndercoverShaders
{
    internal class Material017 : ShaderBaseC11Undercover, ISetShaderValues
    {
        #region Private Fields

        private int lastBumpTextureID1 = -1;
        private int lastBumpTextureID2 = -1;
        private int lastBumpTextureID3 = -1;
        private uint lastHashcodeMappingMatrix1 = 0;
        private uint lastHashcodeMappingMatrix2 = 0;
        private uint lastHashcodeMappingMatrix3 = 0;
        private int lastTextureID1 = -1;
        private int lastTextureID2 = -1;
        private int lastTextureID3 = -1;
        private string name;

        #endregion Private Fields

        #region Public Constructors

        public Material017(Device renderDevice, string shaderDirectory)
            : base(renderDevice)
        {
            this.name = shaderDirectory;
            // base.LoadShader(renderDevice, shaderDirectory + "\\material17.fx");
            //base.SetValue("FogColor", new Color4(0.5f, 0.5f, 0.5f, 0.5f));
        }

        #endregion Public Constructors

        #region Public Properties

        public ShaderBase Effect
        {
            get { return base.effect; }
        }

        public string Name
        {
            get
            {
                return this.name;
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        #endregion Public Properties

        #region Public Methods

        public new void Dispose()
        {
            base.Dispose();
        }

        public void SetProperties(int materialID, MaterialManager materialManager)
        {
            Material material = materialManager.GetMaterial(materialID);

            short TextureID1 = materialManager.GetTextureIDTexture1(materialID);
            short TextureID2 = materialManager.GetTextureIDTexture2(materialID);
            short TextureID3 = materialManager.GetTextureIDTexture3(materialID);
            short BumpTextureID1 = materialManager.GetTextureIDBumbTexture1(materialID);
            short BumpTextureID2 = materialManager.GetTextureIDBumbTexture2(materialID);
            short BumpTextureID3 = materialManager.GetTextureIDBumbTexture3(materialID);

            this.lastTextureID1 = -1;
            this.lastTextureID2 = -1;
            this.lastTextureID3 = -1;
            this.lastBumpTextureID1 = -1;
            this.lastBumpTextureID2 = -1;
            this.lastBumpTextureID3 = -1;

            // base.SetSamplerState(samplerState, 0);
            // base.SetSamplerState(null, 1);
            // base.SetSamplerState(samplerState, 2);
            // base.SetSamplerState(null, 3);
            // base.SetSamplerState(samplerState, 4);
            // base.SetSamplerState(null, 5);
            base.SetTextureUvMatrix(material);

            //effect.SetValue("paintHighLines", false);
            if (this.lastTextureID1 != TextureID1)
            {
                this.lastTextureID1 = TextureID1;

                base.SetTexture(0, material.GetTexture1(materialManager));
                base.SetTexture(1, material.GetBumpTexture1(materialManager));
            }

            if (this.lastTextureID2 != TextureID2)
            {
                this.lastTextureID2 = TextureID2;

                base.SetTexture(2, material.GetTexture2(materialManager));
                base.SetTexture(3, material.GetBumpTexture2(materialManager));
            }
            if (this.lastTextureID3 != 3)
            {
                this.lastTextureID3 = TextureID3;

                base.SetTexture(4, material.GetTexture3(materialManager));
                base.SetTexture(5, material.GetBumpTexture3(materialManager));
            }
        }

        #endregion Public Methods
    }
}